package com.wc._16届国特冲刺营._03动态规划心法_线性DP最优决策链构建.奇怪的段;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/5/7 16:51
 * @description
 * https://www.lanqiao.cn/courses/51805/learning/?id=4072898&compatibility=false
 */
public class Main {
    /**
     * 思路：
     * f[i][j] 表示 前 i 个数字分为 j 组的最大值
     * 遍历 i, 当前 i 是放到 j 里面, 或者是单独 分出一个 j
     * f[i][j] = Math.max(f[i - 1][j], f[i - 1][j - 1]) + a[i] * b[j]
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010, M = 210;
    static long INF = 0x3f3f3f3fL * 0x3f3f3f3f;
    static long[][] f = new long[N][M];
    static long[] a = new long[N], b = new long[M];
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();

        for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
        for (int i = 1; i <= m; i++) b[i] = sc.nextInt();

        for (int i = 0; i <= n; i++) {
            Arrays.fill(f[i], 0, m + 1, -INF);
        }
        f[0][0] = 0;

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                f[i][j] = Math.max(f[i - 1][j], f[i - 1][j - 1]) + a[i] * b[j];
            }
        }
        out.println(f[n][m]);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

